package cn.com.cym.gamezao.util;

import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.List;
import com.itextpdf.layout.element.ListItem;
import com.itextpdf.layout.properties.ListNumberingType;

import java.io.File;
import java.io.IOException;

/**
 * pdf生成的工具类
 */
public class PdfUtil {

    public static Document createPdf(String path){
        try{
            PdfDocument pdf = new PdfDocument(new PdfWriter(new File(path)));
            Document document = new Document(pdf, PageSize.A4);
            //设置边缘; 页边空白; 白边;
            document.setMargins(50f,50f,50f,50f);

            //设置字体
            document.setFont(PdfFontFactory.createFont("STSong-Light","UniGB-UCS2-H"));

            //设置背景颜色
            //document.setBackgroundColor();

            return document;
        }catch (IOException e){
            e.printStackTrace();
        }
        return null;
    }

    public static List formatList(){
        List list = new List().setSymbolIndent(9)
                .setListSymbol(ListNumberingType.DECIMAL);//有序列表
        //.setListSymbol("u2022")//自定义无序列表

        list.add(new ListItem("第一条。"))
                .add(new ListItem("第二条。"));
        return list;
    }

}
